<template>
	<div>
		<div class="box">
			<div class="title">基础信息</div>
			<uni-forms
				ref="form"
				:model="details"
				validate-trigger="bind"
				:label-position="state == 'write' ? 'top' : 'left'"
				label-width="auto">
				<FromItem
					label="线索来源"
					:required="true"
					:state="state"
					name="leadSourceType">
					<view v-if="state == 'readonly'">
						{{
							A_review({
								value: details.leadSourceType,
								dict: {
									list: dict.type.clues_source,
								},
							})
						}}
					</view>

					<ASelectUni
						v-else
						:state="state"
						v-model="details.leadSourceType"
						:dict="{
							list: dict.type.clues_source,
						}"></ASelectUni>
				</FromItem>
				<FromItem
					label="客户类型"
					:required="true"
					:state="state"
					name="customerType">
					<ASelectUni
						v-model="details.customerType"
						:dict="{
							list: config.quotationCustomerTypeIrrList,
							label: 'quotationCustomerTypeName',
							value: 'quotationCustomerTypeId',
						}"
						:state="state"></ASelectUni>
				</FromItem>
				<FromItem
					label="申请类型"
					:required="true"
					:state="state"
					name="applyType">
					<view v-if="state == 'readonly'">
						{{
							A_review({
								value: details.applyType,
								dict: {
									list: dict.type.quota_apply_type,
								},
							})
						}}
					</view>
					<ASelectUni
						v-else
						v-model="details.applyType"
						:dict="{
							list: dict.type.quota_apply_type,
						}"
						:state="state"></ASelectUni>
				</FromItem>
				<FromItem
					label="出租方"
					:required="true"
					:state="state"
					name="lessorId">
					<ASelectUni
						v-model="details.lessorId"
						:dict="{
							list: deptList.company,
							label: 'deptName',
							value: 'deptId',
						}"
						:state="state"
						@change="change_lessorId"></ASelectUni>
				</FromItem>
				<FromItem
					label="承租方"
					:required="true"
					:state="state"
					name="leaseeId">
					<!-- 	<ASelectUni
						v-model="details.leaseeId"
						:dict="{
							list: dictList.testA
						}"
					></ASelectUni> -->
					<User
						:label="details.leaseeName"
						@sure="sure"
						:state="state"></User>
				</FromItem>
				<FromItem
					label="租赁用途"
					:required="true"
					:state="state"
					name="useType">
					<view v-if="state == 'readonly'">
						{{
							A_review({
								value: details.useType,
								dict: {
									list: dict.type.quota_use_type,
								},
							})
						}}
					</view>

					<ASelectUni
						v-else
						v-model="details.useType"
						:dict="{
							list: dict.type.quota_use_type,
						}"
						:state="state"></ASelectUni>
				</FromItem>
				<FromItem
					label="是否厂商业务"
					:required="true"
					:state="state"
					name="vendorType">
					<view v-if="state == 'readonly'">
						{{
							A_review({
								value: details.vendorType,
								dict: {
									list: dict.type.quota_vendor_type,
								},
							})
						}}
					</view>

					<ARadioGroup
						v-else
						v-model="details.vendorType"
						:dict="{
							list: dict.type.quota_vendor_type,
						}"></ARadioGroup>
				</FromItem>
				<FromItem
					label="厂商"
					:required="true"
					:state="state"
					name="vendorName"
					v-if="details.vendorType == '1'">
					<view v-if="state == 'readonly'">
						{{
							A_review({
								value: details.vendorName,
							})
						}}
					</view>
					<AInput v-else type="text" v-model="details.vendorName" />
				</FromItem>
				<FromItem
					label="经销商"
					:required="true"
					:state="state"
					name="agency"
					v-if="config.businessSource == '2'">
					<view v-if="state == 'readonly'">
						{{
							A_review({
								value: details.agency,
							})
						}}
					</view>
					<AInput v-else type="text" v-model="details.agency" />
				</FromItem>
			</uni-forms>
		</div>
	</div>
</template>

<script>
	import User from '@/pages/quota/AForm/user/index.vue';
	import FromItem from '../formItem/index.vue';
	export default {
		name: '',
		components: { FromItem, User },
		dicts: [
			'clues_source',
			'quota_apply_type',
			'quota_use_type',
			'quota_vendor_type',
		],
		props: {},
		inject: [
			'details_provide',
			'config_provide',
			'deptList_provide',
			'state_provide',
		],
		data() {
			return {};
		},
		computed: {
			details() {
				return this.details_provide();
			},
			config() {
				return this.config_provide();
			},
			deptList() {
				return this.deptList_provide();
			},
			state() {
				return this.state_provide();
			},
		},
		filters: {},
		created() {},
		mounted() {},
		methods: {
			sure(val) {
				this.$set(this.details, 'leaseeId', val.item?.customerId);
				this.$set(this.details, 'leaseeName', val.item?.customerName);
				this.$set(
					this.details,
					'customerTypeCode',
					val.item?.customerTypeCode,
				);
				if (val.item?.customerTypeCode == 1) {
					this.details.productList.forEach(item => {
						if (item?.plan?.quantityRequired > 1) {
							item.plan.quantityRequired = 1;
						}
					});
					this.$forceUpdate();
				}
			},
			change_lessorId({ val, item }) {
				this.$set(this.details, 'lessorName', item.deptName);
			},
		},
	};
</script>

<style lang="scss" scoped>
	.box {
		margin: 20rpx;
		padding: 20rpx;
		background-color: #fff;
		border-radius: 8rpx;
		.title {
			border-bottom: 1px solid #e9e9e9;
			font-weight: 500;
			padding-bottom: 10rpx;
			margin-bottom: 10rpx;
		}
	}
</style>
